$(function(){
	judgeSelected();
   $(".df_topw a").hover(
			function(){
				//$(".top_nav a").removeClass("selected");
//				this.style.color  = "#1266bb";
//				var a = $(".selected");
//				a[0].style.color = "#fff";
//				$(".selected").removeClass("selected");
//				this.style.color = "#1266bb";
				$(".selected").removeClass("selected");
			},   //mouseenter
			function(){
				this.style.color = "#fff";
				judgeSelected();
			}  //mouseleave 	 
	   )
	  $("#Map_headerLeftLogo > area:eq(0)").bind("click",{url:"url_index"},dispatcher);
	  $("#Map_headerLeftLogo > area:eq(1)").bind("click",{url:"url_ccic-net"},dispatcher);
	  $(".df_top_contact").bind("click",{url:"url_contact"},dispatcher);
	  $(".df_top_onlineService").bind("click",function(){
		zhiManager.set('moduleType',4);
		zhiManager.expand();
	  });//{url:"url_onlineService"},dispatcher
	//$(".top_search_query").bind("click",query);
   // IE对引用css文件的个数限制为31。 link或style标签视为同一个！ 
   //fnMergeStyleSheet();
	  //2017/3/13
	  /**
	   * $(".df_top_login").click(function(){login();});
	   * $(".df_top_register").click(function(){register();}); 
	   * */
	  $(".df_top_login").click(function(){
		  window.location.href="../../../loginSkin.jsp-loginBackUrl=http---www.95590.cn-cpsg-gcbj-ksbjno3-index.shtml-comCode=31012400.htm"/*tpa=http://www.95590.cn/ebiz/loginSkin.jsp?loginBackUrl=http://www.95590.cn/cpsg/gcbj/ksbjno3/index.shtml?comCode=31012400*/;
	  });
	  $(".df_top_register").click(function(){
		  window.location.href="../../../view/userskin/personRegSkin.jsp-isCarHead=1&loginBackUrl=http---www.95590.cn-cpsg-gcbj-ksbjno3-index.shtml-comCode=31012400.htm"/*tpa=http://www.95590.cn/ebiz/view/userskin/personRegSkin.jsp?isCarHead=1&loginBackUrl=http://www.95590.cn/cpsg/gcbj/ksbjno3/index.shtml?comCode=31012400*/;
	  });
});

//页面点击事件管理
function dispatcher(event){
	var urlName = event.data.url;
	var url = "/";
	var type = "_self";
	if("url_ccic-net"==urlName){
		url = "http://www.ccic-net.com.cn/";
		type = "_blank";
	}else if("url_contact"==urlName){
		url = "/wh/gd/14619.shtml";
		type = "_blank";
		var hostname = location.hostname; //域名
		var flag = ("http://www.95590.cn/ebiz/res/js/2015TopAndButtom/www.95590.cn"==hostname || "http://www.95590.cn/ebiz/res/js/2015TopAndButtom/m.4009666666.cn"==hostname)?true:false;
		if(flag){
			url = "/wh/gd/15843.shtml";
		}
	}else if("url_onlineService"==urlName){
		url = "http://im.95590.cn:7003/EliteWebChat/clientLogin.do?queue=14&visitorGuid=83ca8410-8def-57d7-77a5-e08b2b28bc4a&urlFrom=%E5%AE%98%E7%BD%91(%E6%9C%AA%E7%9F%A5%E6%9D%A5%E6%BA%90)&1486368133710";
	    type = "_blank";
	}
	window.open(url,type);
}

function fnMergeStyleSheet(){
	
	if(!document.styleSheets){ 
		return; 
	} 
	
	 var ie = /*@cc_on !@*/false;
	 if(!ie){
		 return;
	 }
	
	
	
	var aSheet = document.styleSheets, 
	aStyle = document.getElementsByTagName('style');
	aLink = document.getElementsByTagName('link'); 
	if(aStyle.length + aLink.length < 32 || !aSheet[0].cssText){ 
	//document.styleSheets.cssText只有IE支持 
	return; 
	} 
	
	var aCssText = [],aCloneLink = []; 
   
	/***/
	//整合style标签里的css样式  最多删除15个css文件，过多会影响页面加载速度！
	if( aStyle.length >= 1 ){
		
		for(var i=0; i<aStyle.length; i++){ 
			var o = aStyle[i]; 
			aCssText.push(o.innerHTML); 
			if(i<aStyle.length){ 
			o.parentNode.removeChild(o); 
			} 
			} 
		
	}

	//整合link标签里的css样式
	if( aLink.length >= 1 ){
		
		for(var i=0;i<15;i++){ 
			var o = aLink[i]; 
			if(o.getAttribute && o.getAttribute('rel')==='stylesheet'){ 
			if(o.styleSheet){ 
			   aCssText.push(o.styleSheet.cssText); 
			}else{ 
			   aCloneLink.push(o.cloneNode(true)); 
			} 
			if(i<15){ 
			     o.parentNode.removeChild(o); 
			} 
			} 
			} 
		
	}
	
	var oHead = document.getElementsByTagName('head')[0]; 
	for( var i =0;i< aCloneLink.length; i++ ){ 
		var o = aCloneLink[i]; 
		oHead.appendChild(o); 
		aCssText.push(o.styleSheet.cssText); 
		oHead.removeChild(o); 
		} 
		//把所有的样式都复制给第一个标签 
		aSheet[0].cssText += aCssText.join(''); 
        
		var num = 31 - aStyle.length;
		for(var j = num;j<aLink.length;j++){
			oHead.appendChild(aLink[j]);
			//if(aLink[j].getAttribute('href') === '/ebw/res/css/2015TopAndButtom/top_2015.css"'){ alert(1); }
		}
		
}

/*根据地址栏里的url地址 初始化产品选中事件**/
function judgeSelected(){
    var url = document.location.href;
	var obj = $(".df_header_nav > .df_topw");
	var index = 0;//首页
    //产品判断
    if(url.indexOf('/cpsg/gcbj/') != -1){     //汽车险
		index = 1;
	}else if(url.indexOf('/cpsg/lhbj/') != -1){   //旅行险
		index = 2;
	}else if(url.indexOf('/cpsg/ywbj/') != -1){   //意外险
		index = 3;
	}else if(url.indexOf('/cpsg/jtccbj/') != -1){  //财产险
		index = 4;
	}else if(url.indexOf('/cpsg/ylx/') != -1){   //健康险
		index = 5;
	}else if(url.indexOf('/cpsg/thzqcs/') != -1){   //特惠专区
		index = 6;
	}else if(url.indexOf('/bwzx/xszn/zhzc/') != -1){  //服务中心
		index = 7;
	}else if(url.indexOf('/cpsg/employeeLogin/') != -1){//合作专区
		index = 8;
	}
	//else if(url.indexOf('http://jf.95590.cn/') != -1)){//积分商城--非官网内部地址
	//	index = 9;
    //}
	$($(obj).find("a:eq("+index+")")).attr("class", "selected");
}

/*搜索框-搜索事件
   未预定义的关键字 全部跳转到车险首页
**/
function query(){
   var protocol = location.protocol; //协议
   var hostname = location.hostname; //服务器地址或url
   var port = location.port; //端口
   var url = protocol+"//"+hostname+":"+port;

	var keyWords = $(".search_input").val();
	//关键字对比
	if(keyWords.indexOf('车险') != -1 || keyWords.indexOf('企业车') != -1 ){
		url +="/cpsg/gcbj/index.shtml";
		//window.location.href = "../../../../cpsg/gcbj/index.shtml.htm"/*tpa=http://www.95590.cn/cpsg/gcbj/index.shtml*/;
	}else if(keyWords.indexOf('人身险') != -1  || keyWords.indexOf('行李险') != -1){
       url +="/cpsg/gcbj/cxchq/index.shtml";
		//去彩虹桥
	}else if(keyWords.indexOf('旅行险') != -1){
		url +="/cpsg/lhbj/index.shtml";
		//window.location.href = "../../../../cpsg/lhbj/index.shtml.htm"/*tpa=http://www.95590.cn/cpsg/lhbj/index.shtml*/;
	}else if(keyWords.indexOf('意外险') != -1){
        url +="/cpsg/ywbj/index.shtml";
		//window.location.href = "../../../../cpsg/ywbj/index.shtml.htm"/*tpa=http://www.95590.cn/cpsg/ywbj/index.shtml*/;
	}else if(keyWords.indexOf('积分兑换') != -1 || keyWords.indexOf('换积分') != -1 ){
		alert("敬请期待!");
		return;
		//window.location.href = "http://jf.95590.cn/";
	}else if(keyWords.indexOf('会员积分') != -1 || keyWords.indexOf('积分查询') != -1 ){
		alert("敬请期待!");
		return;
		//window.location.href = "http://jf.95590.cn/member/login.html";
	}else if(keyWords == undefined || keyWords=='undefined' || keyWords=='' || keyWords=='null' || keyWords==null){
		url+="/cpsg/gcbj/index.shtml";
		//window.location.href = "../../../../cpsg/gcbj/index.shtml.htm"/*tpa=http://www.95590.cn/cpsg/gcbj/index.shtml*/;
	}else{
		url+="/cpsg/gcbj/index.shtml";
		//window.location.href = "../../../../cpsg/gcbj/index.shtml.htm"/*tpa=http://www.95590.cn/cpsg/gcbj/index.shtml*/;
	}

    window.open(url,"_self");
}
		
